package com.song.user.controller;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.song.user.entity.APIES36kProjectDto;
import com.song.user.entity.User;
import com.song.user.service.UserService;

import basic.commons.page.Page;

@Controller
@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	UserService service;
	
	@RequestMapping("/list")
	public ModelAndView initUpdate(User user) {
		ModelAndView mv = new ModelAndView("/main");
		user.setPage(user.getPage()==null ? new Page() : user.getPage());
		List<User> list =service.selectPage(user);
		mv.addObject("list", list);
		mv.addObject("entity",user);
		return mv;
	}
	
	
	@RequestMapping("/esTest")
	@ResponseBody
	public Map<String,Object> esTest() throws Exception{
		Map<String,Object> map=new HashMap<String, Object>();
//		elasticsearchTemplate.queryForList(query, clazz)
		List<Map<String, Object>> esTest = service.esTest();
		map.put("data", esTest);
		return map;
	}
}
